#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
@file:my_str_join.py.py
@author:liuzhen520@163.com
@date:	2018/04/21
@version: 
    v1.1 2018-04-21 fix bug
    v1.0 2018-04-21 create
@input:	需要就写，不需要就不写
@output:需要就写，不需要就不写

模块功能简述,Get a list of maximum `limit` number of users with user id starting from `start_uid`
"""

name = 'Cali'
age = '18'

# 12 + 23 => 35
# '12' + '23' => '1223'


# 字符串拼接方法1：+
# 操作类型要一致
print(name+age)
# print(name+18)
# # TypeError: must be str, not int
# 效率问题：万恶的+号每出现一次就会在内存中重新开辟一块空间。效率低
result_str = ""
for i in range(1000):
    result_str = result_str+'x m '
print(result_str)


# join
a = ['I', 'Love', 'Python']
print(''.join(a))
# 内置的方法效率通常都会比较高



# format与% 拼接和格式化
msg = "姓名："+name+"，年龄："+age+"。"
print("姓名：", name, "，年龄：", age , "。", sep="")
print(msg)

# % 老版
msg = "%% -> 姓名：%s, 年龄：%s。" %(name, age)
print(msg)

# format 官方推荐
# 方法一: 用位置标注变量
msg = "Format01-> 姓名：{}, 年龄：{}。".format(age, name)
print(msg)

msg = "Format01-> 姓名：{1}, 年龄：{0}。".format(age, name)
print(msg)

# uppack
li = [name, age]
msg = "Format01-> 姓名：{}, 年龄：{}。".format(*li)
print(msg)


# 方法二：关键字方式
msg = "Format02-> 姓名：{name2}, 年龄：{age2}。".format(age2=age, name2=name)
print(msg)

# 方法二：关键字方式
my_format = "Format03-> 姓名：{name2}, 年龄：{age2}。"
msg = my_format.format(age2=age, name2=name)
print(msg)


#### 字符格式化
# 格式：%[(name)][flags][width][.][precision]typecode
print('#'*10)
my_string = "Hello Cali"
# 数字类型：默认是右对齐，字符串：默认左对齐
print("%+10x" % 10)
print("%+10s" % '10')
# print("%04d" % '5')
# TypeError: %d format: a number is required, not str
print("%04d" % 5)
print("%6.3f" % 2.3)
print("%s is number %d python %9.3f !" %(my_string, 10, 123.3))



# 格式：[数据][:][填充字符][对齐方式 <^>][宽度][格式]
#
print('{0:*<10d}'.format(10, 200))
print('{1:*>10}'.format(10, 200))
print('{age2:*^10}'.format(age=10, age2=200))
print('{age2:^10}'.format(age=10, age2=200))

print('{0:*>10.2f}'.format(1/3))
# ******0.33